package org.example;

import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {


    // 结合两篇文档，成功靠自己的力量，找到了资料并成功连接了es客户端并进行了查询
    /**
     * github（GPT告诉我这里有的）
     * https://github.com/elastic/elasticsearch/tree/6.1/docs/java-api/admin
     * 这里讲到了，ES的client需要transport依赖
     * https://github.com/elastic/elasticsearch/blob/6.1/docs/java-api/index.asciidoc#client
     * 可以结合这个文档一起看
     * https://www.elastic.co/guide/en/elasticsearch/reference/6.3/index.html
     * @param args
     * @throws UnknownHostException
     */


    public static void main(String[] args) throws UnknownHostException {

        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));


        System.out.println(client);
        GetResponse response = client.prepareGet("card_index", "doc", "1").get();
        System.out.println(response.getSource());

        client.close();








    }
}